export default {
  //开启命名空间
  namespaced: true,
  
  state: ()=>({
    address: JSON.parse(uni.getStorageSync('address') || '{}'),
    //判断的登录标识
    token: uni.getStorageSync('token')||'',
    userinfo: JSON.parse(uni.getStorageSync('userinfo')||'{}'),
    redirectInfo: null
  }),
  
  mutations:{
    //更新收货地址
    updateAddress(state,address){
      state.address = address
      this.commit('m_user/saveToStorage',['address',address])
    },
    saveToStorage(state,arr){
      uni.setStorageSync(arr[0],JSON.stringify(arr[1]))
    },
    updateUserInfo(state,userinfo){
      state.userinfo = userinfo
      this.commit('m_user/saveToStorage',['userinfo',userinfo])
    },
    updateToken(state,token){
      state.token=token
      this.commit('m_user/saveToStorageToken')
    },
    saveToStorageToken(state){
      uni.setStorageSync('token',state.token)
    },
    updateRedirectInfo(state,info){
      state.redirectInfo = info
      console.log(state.redirectInfo)
    }
  },
  
  getters:{
    addstr(state){
      if(!state.address.provinceName) return ''
      return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
    }
  }
}